﻿Ext.override(Ext.layout.FormLayout, {
    // enable Field prefix / suffix (additional text before/after the input element)
    // by @tof -- http://extjs.com/forum/showthread.php?t=15252
    renderItem: function(c, position, target) {
        if (c && !c.rendered && c.isFormField && c.inputType != 'hidden') {
            var args = [
                c.id,
                c.fieldLabel + (c.allowBlank ? '' : '<span class="x-form-field-asterisk"> * </span>'),

            // bugfix for "FormLayout labelStyle breaks hideLabels, labelAlign and labelWidth"
            // by @condor -- http://www.extjs.com/forum/showthread.php?p=228652#post228652
                (this.labelStyle || '') + ';' + (c.labelStyle || ''),

                this.elementStyle || '',
                typeof c.labelSeparator == 'undefined' ? this.labelSeparator : c.labelSeparator,
                (c.itemCls || this.container.itemCls || '') + (c.hideLabel ? ' x-hide-label' : ''),
                c.clearCls || 'x-form-clear-left'
            ];
            if (typeof position == 'number') {
                position = target.dom.childNodes[position] || null;
            }
            if (position) {
                this.fieldTpl.insertBefore(position, args);
            } else {
                this.fieldTpl.append(target, args);
            }

            var newEl,
                fEl = Ext.get('x-form-el-' + c.id);

            c.render(fEl);

            if (c.prefix) { // Field prefix
                if (c.isXType('trigger')) {
                    newEl = c.wrap.insertHtml('afterBegin', '<span>' + c.prefix + '&nbsp;</span>', true);
                    c.el.setWidth(c.el.getWidth() - c.trigger.getWidth() - newEl.getWidth());
                } else {
                    newEl = fEl.insertHtml('afterBegin', '<span>' + c.prefix + '&nbsp;</span>', true);
                    c.el.setWidth(c.el.getWidth() - newEl.getWidth());
                }
            }

            if (c.suffix) { // custom field suffix addition by @tof
                if (c.isXType('trigger')) {
                    newEl = c.wrap.insertHtml('beforeEnd', '<span>&nbsp;' + c.suffix + '</span>', true);
                    c.el.setWidth(c.el.getWidth() - c.trigger.getWidth() - newEl.getWidth());
                } else {
                    newEl = fEl.insertHtml('beforeEnd', '<span>&nbsp;' + c.suffix + '</span>', true);
                    c.el.setWidth(c.el.getWidth() - newEl.getWidth());
                }
            }
        } else {
            Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments);
        }
    }
});